<?php
  require 'isok.php';
    require 'database.php';
  //检查登录
  
$categories=find('categories');
  if(!empty($_POST)){
      $_POST['user_id']=$_SESSION['userinfo']['id'];      
      $filename= time();
      $name=$_FILES['feature']['name'];
      //解析文件信息
      $pathinfo=pathinfo($name);     
      //文件后缀
      $ext=$pathinfo['extension'];
     $path='/images/feature/'. $filename . '.' . $ext;
   //文件上传
      
       move_uploaded_file($_FILES['feature']['tmp_name'], '..' . $path);
       $_POST['feature']= $path ;  
       $res=insert('posts',$_POST);
       if ($res['status']==1) {
           header('Location:posts.php');
       } else {
           echo '添加失败！';
       }       
       exit();   
  }
  
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>阿里百秀登录管理</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/vendors/ueditor/themes/default/css/umeditor.min.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.php"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="login.php"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="page-title" >
        <h1>写文章</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <form class="row" action="post-add.php" enctype="multipart/form-data" method="post">
        <div class="col-md-9">
          <div class="form-group">
            <label for="title">标题</label>
            <input id="title" class="form-control input-lg" name="title" type="text" placeholder="文章标题">
          </div>
          <div class="form-group">
            <label for="content">标题</label>
            <textarea id="content" class="form-control input-lg" name="content" cols="30" rows="10" placeholder="内容"></textarea>
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <label for="slug">别名</label>
            <input id="slug" class="form-control" name="slug" type="text" placeholder="slug">
            <p class="help-block">https://zce.me/post/<strong>slug</strong></p>
          </div>
          <div class="form-group">
            <label for="feature">特色图像</label>
            <!-- show when image chose -->
            <img class="help-block thumbnail" style="display: none">
            <input id="feature" class="form-control" name="feature" type="file">
          </div>
          <div class="form-group">
            <label for="category">所属分类</label>
            <select id="category" class="form-control" name="category_id">
              <?php foreach ($categories as $key => $val) { ?>
                <option value="<?php echo  $val['id']; ?>"><?php echo $val['name']; ?></option>
              <?php }  ?>
            </select>
          </div>
          <div class="form-group">
            <label for="created">发布时间</label>
            <input id="created" class="form-control" name="created" type="datetime-local">
          </div>
          <div class="form-group">
            <label for="status">状态</label>
            <select id="status" class="form-control" name="status">
              <option value="drafted">草稿</option>
              <option value="published">已发布</option>
            </select>
          </div>
          <div class="form-group">
            <button class="btn btn-primary" type="submit">保存</button>
          </div>
        </div>
      </form>
    </div>
  </div>
<?php include 'aside.php';?>
  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
   <script src="../assets/vendors/ueditor/umeditor.config.js"></script>
  <script src="../assets/vendors/ueditor/umeditor.min.js"></script>
  <script>NProgress.done()</script>
    <script>
      var ue=UM.getEditor('content',{
         initialFrameWidth:'100%',
         initialFrameHeight:320});
    </script>
</body>
</html>
